package com.zx.kitchen.index.common.mvp.model;

import android.app.ProgressDialog;
import android.content.Context;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.TypeReference;
import com.loopj.android.http.RequestParams;
import com.zx.kitchen.index.common.base.Contants;
import com.zx.kitchen.index.common.entity.PrintOrderBean;
import com.zx.kitchen.index.common.mvp.OnResultListener;
import com.zx.kitchen.index.common.utils.HttpUtils;;
import com.zx.kitchen.index.common.utils.PreferenceUtil;

/**
 * Created by Administrator on 2017/3/8.
 */

public class PrintDetailModelImpl implements PrintDetailModel {
    @Override
    public void getFromNet(int requestCode, Context context, int id, boolean type,OnResultListener listener, ProgressDialog progressDialog) {
        RequestParams params = new RequestParams();
        params.put("user_data", PreferenceUtil.getStringData(context, Contants.spToken));
        params.put("id", id);

        if (type){
            HttpUtils.post(context, Contants.PURCHASE_PRINT_ORDER_URL, params, listener, progressDialog);
        }else {
            HttpUtils.post(context, Contants.INDEX_PRINT_ORDER_URL, params, listener, progressDialog);
        }
    }

    @Override
    public PrintOrderBean asyncJson(String str) {
        return JSON.parseObject(str, new TypeReference<PrintOrderBean>() {
        });
    }
}
